package com.ywh.train.logic;

import java.util.Comparator;

import com.ywh.train.Constants;
import com.ywh.train.Util;
import com.ywh.train.bean.TrainQueryInfo;

public class TrainComparator implements Comparator<TrainQueryInfo> {

    public int compare(TrainQueryInfo t1, TrainQueryInfo t2) {
        String t1Type = t1.getTrain_no().substring(0, 1);
        String t2Type = t2.getTrain_no().substring(0, 1);

        if (Util.getSeatAI(t1) == null) {
            return 1;
        }
        if (Util.getSeatAI(t2) == null) {
            return -1;
        }

        // 动车优先
        if (Constants.ISTRAINDFIRST) {
            if (Constants.getTrainPriority(t1Type) > Constants.getTrainPriority(t2Type)) {
                return 1;
            }
            if (Constants.getTrainPriority(t1Type) < Constants.getTrainPriority(t2Type)) {
                return -1;
            }
        }

        // 硬卧优先
        if (Constants.ISHARDSLEEPFIRST) {
            if (Constants.getTrainSeat(t1.getHard_sleeper()) > Constants.getTrainSeat(t2.getHard_sleeper())) {
                return -1;
            }
            if (Constants.getTrainSeat(t1.getHard_sleeper()) < Constants.getTrainSeat(t2.getHard_sleeper())) {
                return 1;
            }
        }

        // 硬座
        if (Constants.getTrainSeat(t1.getHard_seat()) > Constants.getTrainSeat(t2.getHard_seat())) {
            return -1;
        }
        if (Constants.getTrainSeat(t1.getHard_seat()) < Constants.getTrainSeat(t2.getHard_seat())) {
            return 1;
        }

        // 硬卧
        if (Constants.getTrainSeat(t1.getHard_sleeper()) > Constants.getTrainSeat(t2.getHard_sleeper())) {
            return -1;
        }
        if (Constants.getTrainSeat(t1.getHard_sleeper()) < Constants.getTrainSeat(t2.getHard_sleeper())) {
            return 1;
        }

        // 二等座优先
        if (Constants.getTrainSeat(t1.getTwo_seat()) > Constants.getTrainSeat(t2.getTwo_seat())) {
            return -1;
        }
        if (Constants.getTrainSeat(t1.getTwo_seat()) < Constants.getTrainSeat(t2.getTwo_seat())) {
            return 1;
        }

        // 一等座
        if (Constants.getTrainSeat(t1.getOne_seat()) > Constants.getTrainSeat(t2.getOne_seat())) {
            return -1;
        }
        if (Constants.getTrainSeat(t1.getOne_seat()) < Constants.getTrainSeat(t2.getOne_seat())) {
            return 1;
        }

        // 无座
        if (Constants.getTrainSeat(t1.getNone_seat()) > Constants.getTrainSeat(t2.getNone_seat())) {
            return -1;
        }
        if (Constants.getTrainSeat(t1.getNone_seat()) < Constants.getTrainSeat(t2.getNone_seat())) {
            return 1;
        }

        return 0;
    }

}
